/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package utn.frsf.cidisi.upcolbpip.interactionprotocols.impl;

import java.util.Collection;

import org.eclipse.emf.common.notify.Notification;

import org.eclipse.emf.common.util.EList;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;
import org.eclipse.emf.ecore.impl.EObjectImpl;

import org.eclipse.emf.ecore.util.EObjectResolvingEList;

import utn.frsf.cidisi.upcolbpip.b2bcollaborations.PartnerRole;

import utn.frsf.cidisi.upcolbpip.interactionprotocols.BusinessMessage;
import utn.frsf.cidisi.upcolbpip.interactionprotocols.InteractionprotocolsPackage;
import utn.frsf.cidisi.upcolbpip.interactionprotocols.Lifeline;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Lifeline</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link utn.frsf.cidisi.upcolbpip.interactionprotocols.impl.LifelineImpl#getName <em>Name</em>}</li>
 *   <li>{@link utn.frsf.cidisi.upcolbpip.interactionprotocols.impl.LifelineImpl#getPartnerRole <em>Partner Role</em>}</li>
 *   <li>{@link utn.frsf.cidisi.upcolbpip.interactionprotocols.impl.LifelineImpl#getSends <em>Sends</em>}</li>
 *   <li>{@link utn.frsf.cidisi.upcolbpip.interactionprotocols.impl.LifelineImpl#getReceives <em>Receives</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class LifelineImpl extends EObjectImpl implements Lifeline {
	/**
	 * The default value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected static final String NAME_EDEFAULT = null;

	/**
	 * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getName()
	 * @generated
	 * @ordered
	 */
	protected String name = NAME_EDEFAULT;

	/**
	 * The cached value of the '{@link #getPartnerRole() <em>Partner Role</em>}' reference.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getPartnerRole()
	 * @generated
	 * @ordered
	 */
	protected PartnerRole partnerRole;

	/**
	 * The cached value of the '{@link #getSends() <em>Sends</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getSends()
	 * @generated
	 * @ordered
	 */
	protected EList<BusinessMessage> sends;

	/**
	 * The cached value of the '{@link #getReceives() <em>Receives</em>}' reference list.
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @see #getReceives()
	 * @generated
	 * @ordered
	 */
	protected EList<BusinessMessage> receives;

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	protected LifelineImpl() {
		super();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	protected EClass eStaticClass() {
		return InteractionprotocolsPackage.Literals.LIFELINE;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public String getName() {
		return name;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setName(String newName) {
		String oldName = name;
		name = newName;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, InteractionprotocolsPackage.LIFELINE__NAME, oldName, name));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public PartnerRole getPartnerRole() {
		if (partnerRole != null && partnerRole.eIsProxy()) {
			InternalEObject oldPartnerRole = (InternalEObject)partnerRole;
			partnerRole = (PartnerRole)eResolveProxy(oldPartnerRole);
			if (partnerRole != oldPartnerRole) {
				if (eNotificationRequired())
					eNotify(new ENotificationImpl(this, Notification.RESOLVE, InteractionprotocolsPackage.LIFELINE__PARTNER_ROLE, oldPartnerRole, partnerRole));
			}
		}
		return partnerRole;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public PartnerRole basicGetPartnerRole() {
		return partnerRole;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public void setPartnerRole(PartnerRole newPartnerRole) {
		PartnerRole oldPartnerRole = partnerRole;
		partnerRole = newPartnerRole;
		if (eNotificationRequired())
			eNotify(new ENotificationImpl(this, Notification.SET, InteractionprotocolsPackage.LIFELINE__PARTNER_ROLE, oldPartnerRole, partnerRole));
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<BusinessMessage> getSends() {
		if (sends == null) {
			sends = new EObjectResolvingEList<BusinessMessage>(BusinessMessage.class, this, InteractionprotocolsPackage.LIFELINE__SENDS);
		}
		return sends;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	public EList<BusinessMessage> getReceives() {
		if (receives == null) {
			receives = new EObjectResolvingEList<BusinessMessage>(BusinessMessage.class, this, InteractionprotocolsPackage.LIFELINE__RECEIVES);
		}
		return receives;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
		switch (featureID) {
			case InteractionprotocolsPackage.LIFELINE__NAME:
				return getName();
			case InteractionprotocolsPackage.LIFELINE__PARTNER_ROLE:
				if (resolve) return getPartnerRole();
				return basicGetPartnerRole();
			case InteractionprotocolsPackage.LIFELINE__SENDS:
				return getSends();
			case InteractionprotocolsPackage.LIFELINE__RECEIVES:
				return getReceives();
		}
		return super.eGet(featureID, resolve, coreType);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@SuppressWarnings("unchecked")
	@Override
	public void eSet(int featureID, Object newValue) {
		switch (featureID) {
			case InteractionprotocolsPackage.LIFELINE__NAME:
				setName((String)newValue);
				return;
			case InteractionprotocolsPackage.LIFELINE__PARTNER_ROLE:
				setPartnerRole((PartnerRole)newValue);
				return;
			case InteractionprotocolsPackage.LIFELINE__SENDS:
				getSends().clear();
				getSends().addAll((Collection<? extends BusinessMessage>)newValue);
				return;
			case InteractionprotocolsPackage.LIFELINE__RECEIVES:
				getReceives().clear();
				getReceives().addAll((Collection<? extends BusinessMessage>)newValue);
				return;
		}
		super.eSet(featureID, newValue);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public void eUnset(int featureID) {
		switch (featureID) {
			case InteractionprotocolsPackage.LIFELINE__NAME:
				setName(NAME_EDEFAULT);
				return;
			case InteractionprotocolsPackage.LIFELINE__PARTNER_ROLE:
				setPartnerRole((PartnerRole)null);
				return;
			case InteractionprotocolsPackage.LIFELINE__SENDS:
				getSends().clear();
				return;
			case InteractionprotocolsPackage.LIFELINE__RECEIVES:
				getReceives().clear();
				return;
		}
		super.eUnset(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public boolean eIsSet(int featureID) {
		switch (featureID) {
			case InteractionprotocolsPackage.LIFELINE__NAME:
				return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
			case InteractionprotocolsPackage.LIFELINE__PARTNER_ROLE:
				return partnerRole != null;
			case InteractionprotocolsPackage.LIFELINE__SENDS:
				return sends != null && !sends.isEmpty();
			case InteractionprotocolsPackage.LIFELINE__RECEIVES:
				return receives != null && !receives.isEmpty();
		}
		return super.eIsSet(featureID);
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */
	@Override
	public String toString() {
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (name: ");
		result.append(name);
		result.append(')');
		return result.toString();
	}

} //LifelineImpl
